package com.bestv.search.common.service.impl;

import com.bestv.search.common.dao.GenericDao;
import com.bestv.search.common.service.GenericManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.Serializable;
import java.util.List;

public class GenericManagerImpl<T, PK extends Serializable> implements GenericManager<T, PK> {

    protected final Log log = LogFactory.getLog(getClass());

    protected GenericDao<T, PK> genericDao;

    public GenericManagerImpl(GenericDao<T, PK> genericDao) {
        this.genericDao = genericDao;
    }

    public GenericDao<T, PK> getGenericDao() {
        return genericDao;
    }

    public void setGenericDao(GenericDao<T, PK> genericDao) {
        this.genericDao = genericDao;
    }

    @Override
    public boolean exists(PK id) {
        return genericDao.exists(id);
    }

    @Override
    public T get(PK id) {
        return genericDao.get(id);
    }

    @Override
    public List<T> getAll() {
        return genericDao.getAll();
    }

    @Override
    public void remove(PK id) {
        genericDao.remove(id);
    }

    @Override
    public T save(T object) {
        log.debug(object.getClass().getName());
        return genericDao.save(object);
    }

    @Override
    public T saveOrUpdate(T object) {
        return save(object);
    }
}
